package com.tarena.lbs.basic.web.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.basic.web.service.AdminService;
import com.tarena.lbs.pojo.basic.param.AdminParam;
import com.tarena.lbs.pojo.basic.query.AdminQuery;
import com.tarena.lbs.pojo.basic.vo.AdminVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class AdminController {
    @Autowired
    private AdminService adminService;

    @GetMapping("/admin/basic/role/detail")
    public Result<AdminVO> detail() throws BusinessException {
        AdminVO vo = adminService.detail();
        log.debug("返回给前端的VO数据:{}",vo);
        return new Result<>(vo);
    }

    @PostMapping("/admin/basic/role/list")
    public Result<PageResult<AdminVO>> getRoleList(@RequestBody AdminQuery query){
        PageResult<AdminVO> pageResult = adminService.pageList(query);
        return new Result<>(pageResult);
    }

    @PostMapping("/admin/basic/role/add")
    public Result<Void> addAdmin(@RequestBody AdminParam param) throws BusinessException {
        adminService.addAdmin(param);
        return Result.success();
    }

}
